package com.way.fileexplorer.fragments;

import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.way.fileexplorer.R;
import com.way.fileexplorer.activities.FileExploreActivity;
import com.way.fileexplorer.util.Slog;
import com.way.fileexplorer.util.StorageUtil;

public class InternalStorageExplorerFragment extends DetailedListFragment {
    private static InternalStorageExplorerFragment mFragment;
    private static String TAG = "InternalStorageExplorerFragment";

    // bug 201769 begin
    public InternalStorageExplorerFragment() {
        mFragment = this;
    }

    private void initFragment(FileExploreActivity context) {
        mContext = context;
        mFragment = this;
        mTopPath = StorageUtil.getInternalStorage();
        mTopString = mContext
                .getString(R.string.title_section_internal);
        mCurrentString = mTopString;
    }
    // bug 201769 end

    public synchronized static InternalStorageExplorerFragment getInstance(
            FileExploreActivity context) {
        Log.i(TAG,"getInstance()");
        if (mFragment == null) {
            mFragment = new InternalStorageExplorerFragment();
            mFragment.initFragment(context);// bug 201769
        }
        return mFragment;
    }

    public static InternalStorageExplorerFragment getInstance() {
        if (mFragment == null) {
            Slog.e("Context was not init yet, use getInstance(Context) first");
            throw new IllegalStateException();
        }
        return mFragment;
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        // bug 201769 begin
        initFragment((FileExploreActivity) getActivity());
        this.dump("this");
        return super.onCreateView(inflater, container, savedInstanceState);
        // bug 201769 end
    }
    
    public void dump(String tag) {
        Slog.i(TAG, "Now dump state of " + tag);
        Slog.i("hashCode is " + hashCode());
        if (mTopPath != null) {
            Slog.i("mTopPath=" + mTopPath.getAbsolutePath());
        } else {
            Slog.i("mTopPath == null!");
        }
        Slog.i("mContext != null ? " + mContext == null ? String.valueOf(false):String.valueOf(true));
    }
    
    public int getIcon(){
    	return R.drawable.main_device;
    }
    
    public boolean hidePath(){
    	return false;
    }
}
